With the new poliastro
version (0.7.0), a new package is included: NEOs package.
The docstrings of this package states the following:
Functions related to NEOs and different NASA APIs. All of them are coded as part of SOCIS 2017 proposal.
So, first of all, an important question:
NEO stands for near-Earth object. The Center for NEO Studies (CNEOS) defines NEOs as comets and asteroids that have been nudged by the gravitational attraction of nearby planets into orbits that allow them to enter the Earth’s neighborhood.
And what does "near" exactly mean? In terms of orbital elements, asteroids and comets can be considered NEOs if their perihelion (orbit point which is nearest to the Sun) is less than 1.3 au = 1.945 * 108 km from the Sun.
In [1]:
import matplotlib.pyplot as plt
plt.ion()
from astropy import time
from poliastro.twobody.orbit import Orbit
from poliastro.bodies import Earth
from poliastro.plotting import OrbitPlotter
This module make requests to NASA NEO Webservice, so you'll need an internet connection to run the next examples.
The simplest neows
function is orbit_from_name()
, which return an Orbit object given a name:
In [2]:
from poliastro.neos import neows
In [3]:
eros = neows.orbit_from_name('Eros')
frame = OrbitPlotter()
frame.plot(eros, label='Eros')
Out[3]:
You can also search by IAU number or SPK-ID (there is a faster neows.orbit_from_spk_id()
function in that case, although):
In [4]:
ganymed = neows.orbit_from_name('1036') # Ganymed IAU number
amor = neows.orbit_from_name('2001221') # Amor SPK-ID
eros = neows.orbit_from_spk_id('2000433') # Eros SPK-ID
frame = OrbitPlotter()
frame.plot(ganymed, label='Ganymed')
frame.plot(amor, label='Amor')
frame.plot(eros, label='Eros')
Out[4]:
Since neows
relies on Small-Body Database browser to get the SPK-ID given a body name, you can use the wildcards from that browser: *
and ?
.
In [5]:
neows.orbit_from_name('*alley')
In [6]:
eros.epoch.iso
Out[6]:
In [7]:
epoch = time.Time(2458000.0, scale='tdb', format='jd')
eros_november = eros.propagate(epoch)
eros_november.epoch.iso
Out[7]:
Given that we are using NASA APIs, there is a maximum number of requests. If you want to make many requests, it is recommended getting a NASA API key. You can use your API key adding the api_key
parameter to the function:
In [8]:
neows.orbit_from_name('Toutatis', api_key='DEMO_KEY')
Out[8]:
This module can also be used to get NEOs orbit, in the same way that neows
, but it have some advantages (and some disadvantages).
It relies on DASTCOM5 database, a NASA/JPL maintained asteroid and comet database. This database has to be downloaded at least once in order to use this module. According to its README, it is updated typically a couple times per day, but potentially as frequently as once per hour, so you can download it whenever you want the more recently discovered bodies. This also means that, after downloading the file, you can use the database offline.
The file is a ~230 MB zip that you can manually download and unzip in ~/.poliastro
or, more easily, you can use
dastcom5.download_dastcom5()
The main DASTCOM5 advantage over NeoWs is that you can use it to search not only NEOs, but any asteroid or comet. The easiest function is orbit_from_name()
:
In [9]:
from poliastro.neos import dastcom5
In [10]:
atira = dastcom5.orbit_from_name('atira')[0] # NEO
wikipedia = dastcom5.orbit_from_name('wikipedia')[0] # Asteroid, but not NEO.
frame = OrbitPlotter()
frame.plot(atira, label='Atira (NEO)')
frame.plot(wikipedia, label='Wikipedia (asteroid)')
Out[10]:
Keep in mind that this function returns a list of orbits matching your string. This is made on purpose given that there are comets which have several records in the database (one for each orbit determination in history) what allow plots like this one:
In [11]:
halleys = dastcom5.orbit_from_name('1P')
frame = OrbitPlotter()
frame.plot(halleys[0], label='Halley')
frame.plot(halleys[5], label='Halley')
frame.plot(halleys[10], label='Halley')
frame.plot(halleys[20], label='Halley')
frame.plot(halleys[-1], label='Halley')
Out[11]:
While neows
can only be used to get Orbit objects, dastcom5
can also provide asteroid and comet complete database.
Once you have this, you can get specific data about one or more bodies. The complete databases are ndarrays
, so if you want to know the entire list of available parameters, you can look at the dtype
, and they are also explained in
documentation API Reference:
In [12]:
ast_db = dastcom5.asteroid_db()
comet_db = dastcom5.comet_db()
ast_db.dtype.names[:20] # They are more than 100, but that would be too much lines in this notebook :P
Out[12]:
With these ndarrays
you can classify asteroids and comets, sort them, get all their parameters, and whatever comes to your mind.
For example, NEOs can be grouped in several ways. One of the NEOs group is called Atiras
, and is formed by NEOs whose orbits are contained entirely with the orbit of the Earth. They are a really little group, and we can try to plot all of these NEOs using asteroid_db()
:
Talking in orbital terms, Atiras
have an aphelion distance, Q < 0.983 au
and a semi-major axis, a < 1.0 au
.
Visiting documentation API Reference, you can see that DASTCOM5 provides semi-major axis, but doesn't provide aphelion distance. You can get aphelion distance easily knowing perihelion distance (q, QR in DASTCOM5) and semi-major axis Q = 2*a - q
, but there are probably many other ways.
In [13]:
aphelion_condition = 2 * ast_db['A'] - ast_db['QR'] < 0.983
axis_condition = ast_db['A'] < 1.3
atiras = ast_db[aphelion_condition & axis_condition]
The number of Atira NEOs
we use using this method is:
In [14]:
len(atiras)
Out[14]:
Which is consistent with the stats published by CNEOS
Now we're gonna plot all of their orbits, with corresponding labels, just because we love plots :)
In [15]:
from poliastro.twobody.orbit import Orbit
from poliastro.bodies import Earth
earth = Orbit.from_body_ephem(Earth)
We only need to get the 16 orbits from these 16 ndarrays
.
There are two ways:
Orbit.from_classical()
function.NO
property (logical record number in DASTCOM5 database) and the dastcom5.orbit_from_record()
function.The second one seems easier and it is related to the current notebook, so we are going to use that one:
We are going to use ASTNAM
property of DASTCOM5 database:
In [16]:
frame = OrbitPlotter()
frame.plot(earth, label='Earth')
for record in atiras['NO']:
ss = dastcom5.orbit_from_record(record)
frame.plot(ss, color="#666666")
If we needed also the names of each asteroid, we could do:
In [17]:
frame = OrbitPlotter()
frame.plot(earth, label='Earth')
for i in range(len(atiras)):
record = atiras['NO'][i]
label = atiras['ASTNAM'][i].decode().strip() # DASTCOM5 strings are binary
ss = dastcom5.orbit_from_record(record)
frame.plot(ss, label=label)
Finally, another interesting function in dastcom5
is entire_db()
, which is really similar to ast_db
and com_db
, but it returns a Pandas dataframe
instead of a numpy ndarray
. The dataframe has asteroids and comets in it, but in order to achieve that (and a more manageable dataframe), a lot of parameters were removed, and others were renamed:
In [18]:
db = dastcom5.entire_db()
db.columns
Out[18]:
Also, in this function, DASTCOM5 data (specially strings) is ready to use (decoded and improved strings, etc):
In [19]:
db[db.NAME == 'Halley'] # As you can see, Halley is the name of an asteroid too, did you know that?
Out[19]:
Panda offers many functionalities, and can also be used in the same way as the ast_db
and comet_db
functions:
In [20]:
aphelion_condition = (2 * db['A'] - db['QR']) < 0.983
axis_condition = db['A'] < 1.3
atiras = db[aphelion_condition & axis_condition]
In [21]:
len(atiras)
Out[21]:
What? I said they can be used in the same way!
Dont worry :) If you want to know what's happening here, the only difference is that we are now working with comets too, and some comets have a negative semi-major axis!
In [22]:
len(atiras[atiras.A < 0])
Out[22]:
So, rewriting our condition:
In [23]:
axis_condition = (db['A'] < 1.3) & (db['A'] > 0)
atiras = db[aphelion_condition & axis_condition]
len(atiras)
Out[23]: